package com.cg.util;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.core.util.QuickWriter;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
import com.thoughtworks.xstream.io.xml.XppDriver;

import java.io.Writer;

public class TextToXmlUtils {

	public static String textMessageToXml(Object obj){
		xstream.alias("xml",obj.getClass());
		return xstream.toXML(obj);                                                                               
	}
	

	public static XStream xstream=new XStream(new XppDriver(){           
	public HierarchicalStreamWriter createWriter(Writer out){
	             return new PrettyPrintWriter(out){
	              boolean cdata= true;
	               protected void writeText(QuickWriter writer,String text){
	                if(cdata){
	               writer.write("<![CDATA[");
	               writer.write(text);
	               writer.write("]]>");
	               }else{
	              writer.write(text);
	                }
	                 }
	              };
	}
	});
}
